<template>
  <div class="ratingselect">
    <div class="rating_type">
      <div class="rating_type_content">
        <span class="block positive" @click="select(2, $event)" :class="{'active':selectType.Types === 2}">
        {{selectDesc.all}}
        <span class="count" v-text="ratingscount.length"></span>
      </span>
        <span class="block positive" @click="select(0, $event)" :class="{'active':selectType.Types === 0}">
        {{selectDesc.positive}} <span class="count" v-text="positives.length"></span>
      </span>
        <span class="block negative" @click="select(1, $event)" :class="{'active':selectType.Types === 1}">
        {{selectDesc.negative}} <span class="count" v-text="negatives.length"></span>
      </span>
      </div>
    </div>
    <div class="switch" @click="toggleContent($event)" :class="{'on':onlyContent.onlyContent}">
      <i class="iconfont">&#xe64a;</i>
      <span class="text">只看有内容评价</span>
    </div>
  </div>
</template>

<script>
  var Positive = 0  //满意的
  var Negative = 1  //不满意的评价
  var All = 2
  const Types = {'Types': All}
  var onlyContent = {'onlyContent': false}
  export default {
    props: {
      ratings: {
        type: Array,
        default() {
          return [];
        }
      },
      selectType: {   /* 选择的评价的类型 */
        type: Object,
        default() {
          return Types
        }
      },
      selectDesc: {
        type: Object,
        default() {
          return {
            all: '全部',
            positive: '满意',
            negative: '不满意'
          }
        }
      },
      onlyContent: {
        type: Object,
        default() {
          return onlyContent
        }
      }
    },
    computed: {
      ratingscount() {
        return this.ratings
      },
      positives() {
       return this.ratings.filter((rating) => {
         return rating.rateType === Positive
        })
      },
      negatives() {
        return this.ratings.filter((rating) => {
          return rating.rateType === Negative
        })
      }
    },
    methods: {
      select(type, event) {
        if(!event._constructed) {
          return
        }
        this.selectType.Types = type
        this.$emit('select-type',type)
      },
      toggleContent(event) {
        if(!event._constructed) {
          return
        }
        this.onlyContent.onlyContent = !this.onlyContent.onlyContent
        this.$emit('content-toggle', this.onlyContent)
      }
    }
  }
</script>

<style lang="scss" rel="stylesheet/scss" scoped>
  .ratingselect {
    .rating_type {
      padding: 0 18px;
      .rating_type_content {
        padding: 12px 0 18px 0;
        border-bottom: 1px solid rgba(7,17,27,0.2);
        font-size: 0;
        .block {
          display: inline-block;
          padding: 8px 12px;
          font-size: 14px;
          margin-right: 8px;
          border-radius: 2px;
          color: rgb(77,85,93);
          &.active {
            color: #fff;
          }
          &.positive {
            background-color: rgba(0,160,220,0.2);
            &.active {
              background-color: rgb(0,160,220);
            }
          }
          &.negative {
            background-color: rgba(77,85,93,0.2);
            &.active {
              background-color: rgb(77,85,93);
            }
          }

          .count {
            font-size: 9px;
            margin-left: 1px;
          }
        }
      }
    }
    .switch {
      padding: 12px 18px;
      line-height: 24px;
      border-bottom: 1px solid rgba(7,17,27,0.2);
      color: rgb(147,153,159);
      &.on {
        .iconfont {
          color: #00c850;
        }
      }
      .iconfont {
        display: inline-block;
        vertical-align: top;
        font-size: 24px;
        margin-right: 3px;
        color: #B7BBBF;
      }
      .text {
        font-size: 12px;
      }
    }
  }
</style>